package main

import (
	"fmt"
)

func main() {
	//func1(1, 2, 3, 4)
	/*
		for i := 0; i < 3; i++ {
			defer func() {
				fmt.Println(i)
			}()
		}
		A()
		B()
		C()
		var fs = [4]func(){}
		for i := 0; i < 4; i++ {
			defer fmt.Println("defer i = ", i)
			defer func() {
				fmt.Println("defer_closure i = ", i)
			}()
			fs[i] = func() {
				fmt.Println("closure i = ", i)
			}
		}
		for _, f := range fs {
			f()
		}
	*/
	a := 1
	//a := 2
	func1(&a)
	fmt.Println(a)
}

func func1(a *int) {
	*a = 3
	fmt.Println(*a)
}

func A() {
	fmt.Println("Panic in A")
	///panic("Panic in A")
}
func B() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("Recover in B")
		}
	}()
	panic("Panic in B")
}
func C() {
	panic("Panic in C")
}
